summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraliaspider2015-11-09 21:17:01 +0100
committeraliaspider2015-11-09 21:17:01 +0100
commit909963506109d475732feeff367e5e2a74974344 (patch)
tree12196ed2c8701256317332e5ec5a113c4fcf6be2
parente144a0acc4854ad80f9e6945f4d94223ee865d78 (diff)
downloadsnes9x2002-909963506109d475732feeff367e5e2a74974344.tar.gz
snes9x2002-909963506109d475732feeff367e5e2a74974344.tar.bz2
snes9x2002-909963506109d475732feeff367e5e2a74974344.zip
add sound interpolation
-rw-r--r--libretro/libretro.c2
-rw-r--r--src/soundux.c40
2 files changed, 41 insertions, 1 deletions
diff --git a/libretro/libretro.c b/libretro/libretro.c
index c1665b4..b7aa69b 100644
--- a/libretro/libretro.c
+++ b/libretro/libretro.c
@@ -252,6 +252,8 @@ static void snes_init (void)
Settings.SpeedHacks = TRUE;
Settings.HBlankStart = (256 * Settings.H_Max) / SNES_HCOUNTER_MAX;
+
+ Settings.InterpolatedSound = TRUE;
/*
Settings.SoundPlaybackRate = 5;
Settings.Stereo = TRUE;
diff --git a/src/soundux.c b/src/soundux.c
index 60d5540..67f7127 100644
--- a/src/soundux.c
+++ b/src/soundux.c
@@ -187,6 +187,7 @@ void S9xFixSoundAfterSnapshotLoad()
S9xSetSoundFrequency(i, SoundData.channels[i].hertz);
SoundData.channels [i].envxx = SoundData.channels [i].envx << ENVX_SHIFT;
SoundData.channels [i].next_sample = 0;
+ SoundData.channels [i].interpolate = 0;
SoundData.channels [i].previous [0] = (int32) SoundData.channels [i].previous16 [0];
SoundData.channels [i].previous [1] = (int32) SoundData.channels [i].previous16 [1];
}
@@ -380,6 +381,11 @@ static void MixStereo(int sample_count)
ch->sample_pointer = SOUND_DECODE_LENGTH - 1;
ch->next_sample = ch->block[ch->sample_pointer];
+ ch->interpolate = 0;
+
+ if (Settings.InterpolatedSound && freq0 < FIXED_POINT && !mod)
+ ch->interpolate = ((ch->next_sample - ch->sample) *
+ (long) freq0) / (long) FIXED_POINT;
}
VL = (ch->sample * ch-> left_vol_level) / 128;
VR = (ch->sample * ch->right_vol_level) / 128;
@@ -587,17 +593,49 @@ static void MixStereo(int sample_count)
else
ch->next_sample = ch->block [ch->sample_pointer];
- if (ch->type != SOUND_SAMPLE)
+ if (ch->type == SOUND_SAMPLE)
{
+ if (Settings.InterpolatedSound && freq < FIXED_POINT && !mod)
+ {
+ ch->interpolate = ((ch->next_sample - ch->sample) *
+ (long) freq) / (long) FIXED_POINT;
+ ch->sample = (int16_t)(ch->sample + (((ch->next_sample - ch->sample) *
+ (long)(ch->count)) / (long) FIXED_POINT));
+ }
+ else
+ ch->interpolate = 0;
+ }
+ else
+ {
+#if 1
+ // Snes9x 1.53's SPC_DSP.cpp, by blargg
+ int feedback = (so.noise_gen << 13) ^ (so.noise_gen << 14);
+ so.noise_gen = (feedback & 0x4000) ^ (so.noise_gen >> 1);
+ ch->sample = (so.noise_gen << 17) >> 17;
+ ch->interpolate = 0;
+#else
for (; VL > 0; VL--)
if ((so.noise_gen <<= 1) & 0x80000000L)
so.noise_gen ^= 0x0040001L;
ch->sample = (so.noise_gen << 17) >> 17;
+#endif
}
VL = (ch->sample * ch-> left_vol_level) / 128;
VR = (ch->sample * ch->right_vol_level) / 128;
}
+ else
+ {
+ if (ch->interpolate)
+ {
+ int32_t s = (int32_t) ch->sample + ch->interpolate;
+
+ CLIP16(s);
+ ch->sample = (int16_t) s;
+ VL = (ch->sample * ch-> left_vol_level) / 128;
+ VR = (ch->sample * ch->right_vol_level) / 128;
+ }
+ }
if (pitch_mod & (1 << (J + 1)))
wave [I / 2] = ch->sample * ch->envx;