Skip to content

Commit

Permalink
AUDIO: Explicitly instantiate & name RandomSource used by MAME OPL
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed May 23, 2011
1 parent f1a7ec7 commit e7c642b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion audio/fmopl.h
Expand Up @@ -23,7 +23,10 @@
#define SOUND_FMOPL_H

#include "common/scummsys.h"
#include "common/str.h"

namespace Common {
class String;
}

namespace OPL {

Expand Down
14 changes: 12 additions & 2 deletions audio/softsynth/opl/mame.cpp
Expand Up @@ -546,7 +546,7 @@ inline void OPL_CALC_RH(FM_OPL *OPL, OPL_CH *CH) {
// but EG_STEP = 96.0/EG_ENT, and WHITE_NOISE_db=6.0. So, that's equivalent to
// int(OPL->rnd.getRandomBit() * EG_ENT/16). We know that EG_ENT is 4096, or 1024,
// or 128, so we can safely avoid any FP ops.
int whitenoise = OPL->rnd.getRandomBit() * (EG_ENT>>4);
int whitenoise = OPL->rnd->getRandomBit() * (EG_ENT>>4);

int tone8;

Expand Down Expand Up @@ -1126,6 +1126,15 @@ FM_OPL *OPLCreate(int type, int clock, int rate) {
OPL->rate = rate;
OPL->max_ch = max_ch;

// Init the random source. Note: We use a fixed name for it here.
// So if multiple FM_OPL objects exist in parallel, then their
// random sources will have an equal name. At least in the
// current EventRecorder implementation, this causes no problems;
// but this is probably not guaranteed.
// Alas, it does not seem worthwhile to bother much with this
// at the time, so I am leaving it as it is.
OPL->rnd = new Common::RandomSource("mame");

/* init grobal tables */
OPL_initalize(OPL);

Expand All @@ -1134,9 +1143,10 @@ FM_OPL *OPLCreate(int type, int clock, int rate) {
return OPL;
}

/* ---------- Destroy one of vietual YM3812 ---------- */
/* ---------- Destroy one of virtual YM3812 ---------- */
void OPLDestroy(FM_OPL *OPL) {
OPL_UnLockTable();
delete OPL->rnd;
free(OPL);
}

Expand Down
2 changes: 1 addition & 1 deletion audio/softsynth/opl/mame.h
Expand Up @@ -147,7 +147,7 @@ typedef struct fm_opl_f {
OPL_UPDATEHANDLER UpdateHandler; /* stream update handler */
int UpdateParam; /* stream update parameter */

Common::RandomSource rnd;
Common::RandomSource *rnd;
} FM_OPL;

/* ---------- Generic interface section ---------- */
Expand Down

0 comments on commit e7c642b

Please sign in to comment.