SPC: Use 32040hz output rate for SPC (same as bsnes/snes9x) - fixes Fievel Goes West

This commit is contained in:
Sour 2020-02-27 21:34:04 -05:00
parent 31630ad04d
commit bc6067707c
5 changed files with 15 additions and 22 deletions

View file

@ -6,6 +6,7 @@
#include "RewindManager.h" #include "RewindManager.h"
#include "VideoRenderer.h" #include "VideoRenderer.h"
#include "WaveRecorder.h" #include "WaveRecorder.h"
#include "Spc.h"
#include "Msu1.h" #include "Msu1.h"
#include "../Utilities/Equalizer.h" #include "../Utilities/Equalizer.h"
#include "../Utilities/blip_buf.h" #include "../Utilities/blip_buf.h"
@ -70,15 +71,8 @@ void SoundMixer::PlayAudioBuffer(int16_t* samples, uint32_t sampleCount)
_leftSample = samples[0]; _leftSample = samples[0];
_rightSample = samples[1]; _rightSample = samples[1];
int16_t *out = nullptr; int16_t *out = _sampleBuffer;
uint32_t count = 0; uint32_t count = _resampler->Resample(samples, sampleCount, cfg.SampleRate, out);
if(cfg.SampleRate == SoundResampler::SpcSampleRate && cfg.DisableDynamicSampleRate) {
out = samples;
count = sampleCount;
} else {
count = _resampler->Resample(samples, sampleCount, cfg.SampleRate, _sampleBuffer);
out = _sampleBuffer;
}
shared_ptr<Msu1> msu1 = _console->GetMsu1(); shared_ptr<Msu1> msu1 = _console->GetMsu1();
if(msu1) { if(msu1) {
@ -126,7 +120,7 @@ void SoundMixer::ProcessEqualizer(int16_t* samples, uint32_t sampleCount)
cfg.Band11Gain, cfg.Band12Gain, cfg.Band13Gain, cfg.Band14Gain, cfg.Band15Gain, cfg.Band11Gain, cfg.Band12Gain, cfg.Band13Gain, cfg.Band14Gain, cfg.Band15Gain,
cfg.Band16Gain, cfg.Band17Gain, cfg.Band18Gain, cfg.Band19Gain, cfg.Band20Gain cfg.Band16Gain, cfg.Band17Gain, cfg.Band18Gain, cfg.Band19Gain, cfg.Band20Gain
}; };
_equalizer->UpdateEqualizers(bandGains, SoundResampler::SpcSampleRate); _equalizer->UpdateEqualizers(bandGains, Spc::SpcSampleRate);
_equalizer->ApplyEqualizer(sampleCount, samples); _equalizer->ApplyEqualizer(sampleCount, samples);
} }

View file

@ -1,6 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "SoundResampler.h" #include "SoundResampler.h"
#include "Console.h" #include "Console.h"
#include "Spc.h"
#include "EmuSettings.h" #include "EmuSettings.h"
#include "SoundMixer.h" #include "SoundMixer.h"
#include "VideoRenderer.h" #include "VideoRenderer.h"
@ -9,8 +10,8 @@
SoundResampler::SoundResampler(Console *console) SoundResampler::SoundResampler(Console *console)
{ {
_console = console; _console = console;
_blipBufLeft = blip_new(SoundResampler::SpcSampleRate); _blipBufLeft = blip_new(Spc::SpcSampleRate);
_blipBufRight = blip_new(SoundResampler::SpcSampleRate); _blipBufRight = blip_new(Spc::SpcSampleRate);
} }
SoundResampler::~SoundResampler() SoundResampler::~SoundResampler()
@ -75,13 +76,13 @@ double SoundResampler::GetTargetRateAdjustment()
void SoundResampler::UpdateTargetSampleRate(uint32_t sampleRate) void SoundResampler::UpdateTargetSampleRate(uint32_t sampleRate)
{ {
uint32_t spcSampleRate = SoundResampler::SpcSampleRate; uint32_t spcSampleRate = Spc::SpcSampleRate;
if(_console->GetSettings()->GetVideoConfig().IntegerFpsMode) { if(_console->GetSettings()->GetVideoConfig().IntegerFpsMode) {
//Adjust sample rate when running at 60.0 fps instead of 60.1 //Adjust sample rate when running at 60.0 fps instead of 60.1
switch(_console->GetRegion()) { switch(_console->GetRegion()) {
default: default:
case ConsoleRegion::Ntsc: spcSampleRate = (uint32_t)(SoundResampler::SpcSampleRate * (60.0 / 60.0988118623484)); break; case ConsoleRegion::Ntsc: spcSampleRate = (uint32_t)(Spc::SpcSampleRate * (60.0 / 60.0988118623484)); break;
case ConsoleRegion::Pal: spcSampleRate = (uint32_t)(SoundResampler::SpcSampleRate * (50.0 / 50.00697796826829)); break; case ConsoleRegion::Pal: spcSampleRate = (uint32_t)(Spc::SpcSampleRate * (50.0 / 50.00697796826829)); break;
} }
} }
@ -112,8 +113,8 @@ uint32_t SoundResampler::Resample(int16_t *inSamples, uint32_t sampleCount, uint
blip_end_frame(_blipBufLeft, sampleCount); blip_end_frame(_blipBufLeft, sampleCount);
blip_end_frame(_blipBufRight, sampleCount); blip_end_frame(_blipBufRight, sampleCount);
uint32_t resampledCount = blip_read_samples(_blipBufLeft, outSamples, SoundResampler::SpcSampleRate, true); uint32_t resampledCount = blip_read_samples(_blipBufLeft, outSamples, Spc::SpcSampleRate, true);
blip_read_samples(_blipBufRight, outSamples + 1, SoundResampler::SpcSampleRate, true); blip_read_samples(_blipBufRight, outSamples + 1, Spc::SpcSampleRate, true);
return resampledCount; return resampledCount;
} }

View file

@ -6,9 +6,6 @@ struct blip_t;
class SoundResampler class SoundResampler
{ {
public:
static constexpr int SpcSampleRate = 32000;
private: private:
Console *_console; Console *_console;

View file

@ -48,7 +48,7 @@ Spc::Spc(Console* console)
_operandB = 0; _operandB = 0;
_enabled = true; _enabled = true;
_clockRatio = (double)2048000 / _console->GetMasterClockRate(); _clockRatio = (double)(Spc::SpcSampleRate * 64) / _console->GetMasterClockRate();
} }
#ifndef DUMMYSPC #ifndef DUMMYSPC
@ -359,7 +359,7 @@ void Spc::ProcessEndFrame()
{ {
Run(); Run();
_clockRatio = (double)2048000 / _console->GetMasterClockRate(); _clockRatio = (double)(Spc::SpcSampleRate * 64) / _console->GetMasterClockRate();
int sampleCount = _dsp->sample_count(); int sampleCount = _dsp->sample_count();
if(sampleCount != 0) { if(sampleCount != 0) {

View file

@ -22,6 +22,7 @@ class Spc : public ISerializable
public: public:
static constexpr int SpcRamSize = 0x10000; static constexpr int SpcRamSize = 0x10000;
static constexpr int SpcRomSize = 0x40; static constexpr int SpcRomSize = 0x40;
static constexpr int SpcSampleRate = 32040;
private: private:
static constexpr int SampleBufferSize = 0x20000; static constexpr int SampleBufferSize = 0x20000;