Skip to content

Commit

Permalink
Added user configurable frequency offset for surroundopl. Thanks to @…
Browse files Browse the repository at this point in the history
  • Loading branch information
PalMusicFan authored and binarymaster committed Feb 16, 2019
1 parent 881056d commit 8877361
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/opl.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class Copl

// Emulation only: fill buffer
virtual void update(short *buf, int samples) {}

// Set surroundopl offset
virtual void set_offset(double offset) {}

protected:
int currChip; // currently selected OPL chip number
Expand Down
13 changes: 12 additions & 1 deletion src/surroundopl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ CSurroundopl::CSurroundopl(COPLprops *a, COPLprops *b, bool output16bit)

this->lbuf = new short[this->bufsize];
this->rbuf = new short[this->bufsize];

// Default frequency offset for surroundopl is defined by FREQ_OFFSET.
this->offset = FREQ_OFFSET;
};

CSurroundopl::~CSurroundopl()
Expand Down Expand Up @@ -127,7 +130,7 @@ void CSurroundopl::write(int reg, int val)
// Adjust the frequency and calculate the new FNum
//double dbNewFNum = (dbOriginalFreq+(dbOriginalFreq/FREQ_OFFSET)) / (50000.0 * pow(2, iNewBlock - 20));
//#define calcFNum() ((dbOriginalFreq+(dbOriginalFreq/FREQ_OFFSET)) / (50000.0 * pow(2, iNewBlock - 20)))
#define calcFNum() ((dbOriginalFreq+(dbOriginalFreq/FREQ_OFFSET)) / (49716.0 * pow(2.0, iNewBlock - 20)))
#define calcFNum() ((dbOriginalFreq+(dbOriginalFreq/this->offset)) / (49716.0 * pow(2.0, iNewBlock - 20)))
double dbNewFNum = calcFNum();

// Make sure it's in range for the OPL chip
Expand Down Expand Up @@ -241,3 +244,11 @@ void CSurroundopl::setchip(int n)
this->oplA.opl->setchip(n);
this->oplB.opl->setchip(n);
}

void CSurroundopl::set_offset(double offset)
{
if (offset != 0)
{
this->offset = offset;
}
}
2 changes: 2 additions & 0 deletions src/surroundopl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class CSurroundopl: public Copl
uint8_t iTweakedFMReg[2][256];
uint8_t iCurrentTweakedBlock[2][9]; // Current value of the Block in the tweaked OPL chip
uint8_t iCurrentFNum[2][9]; // Current value of the FNum in the tweaked OPL chip
double offset; // User configurable frequency offset for surroundopl

public:

Expand All @@ -71,6 +72,7 @@ class CSurroundopl: public Copl

void init();
void setchip(int n);
void set_offset(double offset);
};

#endif

0 comments on commit 8877361

Please sign in to comment.