Skip to content

Commit

Permalink
Minor YM2413 performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 14, 2024
1 parent d4e65ab commit e8f6dc0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/YM2413.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ YM2413::YM2413()
m_RegisterF2 = 0;
m_CurrentSample = 0;
m_bEnabled = false;
m_iCyclesPerSample = 0;
}

YM2413::~YM2413()
Expand All @@ -50,6 +51,7 @@ void YM2413::Init(int clockRate)
void YM2413::Reset(int clockRate)
{
m_iClockRate = clockRate;
m_iCyclesPerSample = m_iClockRate / GS_AUDIO_SAMPLE_RATE;
m_ElapsedCycles = 0;
m_CurrentSample = 0;
m_iCycleCounter = 0;
Expand Down Expand Up @@ -141,10 +143,9 @@ void YM2413::Sync()
}

m_iSampleCounter++;
int cyclesPerSample = m_iClockRate / GS_AUDIO_SAMPLE_RATE;
if (m_iSampleCounter >= cyclesPerSample)
if (m_iSampleCounter >= m_iCyclesPerSample)
{
m_iSampleCounter -= cyclesPerSample;
m_iSampleCounter -= m_iCyclesPerSample;

m_pBuffer[m_iBufferIndex] = m_CurrentSample;
m_pBuffer[m_iBufferIndex + 1] = m_CurrentSample;
Expand Down
1 change: 1 addition & 0 deletions src/YM2413.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class YM2413
private:
int m_iCycleCounter;
int m_iSampleCounter;
int m_iCyclesPerSample;
s16* m_pBuffer;
int m_iBufferIndex;
int m_ElapsedCycles;
Expand Down

0 comments on commit e8f6dc0

Please sign in to comment.