Skip to content

Commit

Permalink
NES: Fixed EPSM sound quality issues
Browse files Browse the repository at this point in the history
The 500kHz to ~48kHz downsampling was causing problems
  • Loading branch information
SourMesen committed Oct 2, 2024
1 parent 4f423a1 commit 1affcd1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Core/NES/Epsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@ uint64_t Epsm::GetTargetClock()

void Epsm::Exec()
{
constexpr int clocksPerSample = 16;
constexpr int clocksPerSample = 144;

uint64_t targetClock = GetTargetClock();

while(_clockCounter < targetClock) {
_clockCounter++;
_opn.Exec();

if((_clockCounter & (clocksPerSample - 1)) == 0) {
if(++_sampleClockCounter == clocksPerSample) {
_opn.GenerateSamples(_samples);
_sampleClockCounter = 0;
}
}
}
Expand Down Expand Up @@ -101,6 +102,7 @@ void Epsm::Serialize(Serializer& s)
SV(_addr);
SV(_data);
SV(_masterClockRate);
SV(_sampleClockCounter);

SV(_opn);
}
1 change: 1 addition & 0 deletions Core/NES/Epsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Epsm : public IAudioProvider, public INesMemoryHandler, public ISerializab

uint64_t _masterClockRate = 0;
uint64_t _clockCounter = 0;
uint8_t _sampleClockCounter = 0;
uint8_t _prevValue = 0;
uint8_t _data = 0;
uint8_t _addr = 0;
Expand Down
1 change: 1 addition & 0 deletions Core/NES/OpnInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class OpnInterface : public ymfm::ymfm_interface, public ISerializable
_adpcmRom.resize(0x2000);

_console = console;
_opn.set_fidelity(ymfm::OPN_FIDELITY_MED);
_opn.reset();
}

Expand Down

0 comments on commit 1affcd1

Please sign in to comment.