try to improve audio sync

This commit is contained in:
Daryl Borth 2018-08-19 16:38:33 -06:00
parent 860d77a094
commit c77b4f4963
7 changed files with 30 additions and 25 deletions

View File

@ -85,6 +85,7 @@ GCMixSamples ()
static void FinalizeSamplesCallback (void *data)
{
LWP_MutexLock(audiomutex);
UpdatePlaybackRateWithDynamicRate();
S9xFinalizeSamples();
LWP_MutexUnlock(audiomutex);
}

View File

@ -3100,7 +3100,6 @@ static int MenuSettingsVideo()
int ret;
int i = 0;
bool firstRun = true;
bool reset_sfx = false;
OptionList options;
sprintf(options.name[i++], "Rendering");
@ -3205,17 +3204,18 @@ static int MenuSettingsVideo()
break;
case 8:
GCSettings.sfxOverclock++;
if (GCSettings.sfxOverclock > 2)
if (GCSettings.sfxOverclock > 2) {
GCSettings.sfxOverclock = 0;
}
switch(GCSettings.sfxOverclock)
{
case 0: Settings.SuperFXSpeedPerLine = 0.417 * 10.5e6; reset_sfx = true; break;
case 1: Settings.SuperFXSpeedPerLine = 0.417 * 40.5e6; reset_sfx = true; break;
case 2: Settings.SuperFXSpeedPerLine = 0.417 * 60.5e6; reset_sfx = true; break;
case 0: Settings.SuperFXSpeedPerLine = 0.417 * 10.5e6; break;
case 1: Settings.SuperFXSpeedPerLine = 0.417 * 40.5e6; break;
case 2: Settings.SuperFXSpeedPerLine = 0.417 * 60.5e6; break;
}
if (reset_sfx) S9xResetSuperFX();
S9xResetSuperFX();
S9xReset();
break;
break;
}
if(ret >= 0 || firstRun)

View File

@ -483,7 +483,7 @@ DefaultSettings ()
Settings.Stereo = true;
Settings.ReverseStereo = true;
Settings.SoundPlaybackRate = 48000;
Settings.SoundInputRate = 32000;
Settings.SoundInputRate = 31970;
Settings.DynamicRateControl = true;
// Graphics

View File

@ -390,20 +390,23 @@ int S9xGetSampleCount (void)
}
#ifdef GEKKO
void S9xIncreaseDynamicRateMultiplier ()
{
if(spc::dynamic_rate_multiplier != 1.005) {
spc::dynamic_rate_multiplier = 1.005;
static double new_dynamic_rate_multiplier = 1.0;
void UpdatePlaybackRateWithDynamicRate() {
if(spc::dynamic_rate_multiplier != new_dynamic_rate_multiplier) {
spc::dynamic_rate_multiplier = new_dynamic_rate_multiplier;
UpdatePlaybackRate();
}
}
void S9xResetDynamicRateMultiplier ()
static inline void IncreaseDynamicRateMultiplier ()
{
if(spc::dynamic_rate_multiplier != 1.0) {
spc::dynamic_rate_multiplier = 1.0;
UpdatePlaybackRate();
}
new_dynamic_rate_multiplier = 1.01;
}
static inline void ResetDynamicRateMultiplier ()
{
new_dynamic_rate_multiplier = 1.0;
}
#endif
@ -413,17 +416,14 @@ void S9xFinalizeSamples (void)
if (!Settings.Mute)
{
if(!spc::sound_in_sync) {
S9xIncreaseDynamicRateMultiplier();
}
drop_current_msu1_samples = FALSE;
if (!spc::resampler->push((short *) spc::landing_buffer, spc_core->sample_count()))
{
/* We weren't able to process the entire buffer. Potential overrun. */
spc::sound_in_sync = FALSE;
S9xClearSamples();
if (Settings.SoundSync && !Settings.TurboMode)
return;
@ -455,7 +455,10 @@ void S9xFinalizeSamples (void)
spc::sound_in_sync = FALSE;
if(spc::sound_in_sync) {
S9xResetDynamicRateMultiplier ();
ResetDynamicRateMultiplier ();
}
else {
IncreaseDynamicRateMultiplier ();
}
spc_core->set_output((SNES_SPC::sample_t *) spc::landing_buffer, spc::buffer_size >> 1);

View File

@ -211,6 +211,7 @@ void S9xSetSoundControl (uint8);
void S9xSetSoundMute (bool8);
void S9xLandSamples (void);
void S9xFinalizeSamples (void);
void UpdatePlaybackRateWithDynamicRate();
void S9xClearSamples (void);
bool8 S9xMixSamples (uint8 *, int);
void S9xSetSamplesAvailableCallback (apu_callback, void *);

View File

@ -378,7 +378,7 @@ void InitializeSnes9x() {
if (!S9xInitAPU ())
ExitApp();
S9xInitSound (32, 0); // Initialise Sound System
S9xInitSound (64, 0); // Initialise Sound System
// Initialise Graphics
setGFX ();

View File

@ -638,7 +638,7 @@ ResetVideo_Emu ()
else
ResetFbWidth(512, rmode);
Settings.SoundInputRate = 32000;
Settings.SoundInputRate = 31970;
UpdatePlaybackRate();
}