aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2004-03-13 18:44:10 +0000
committerMax Horn2004-03-13 18:44:10 +0000
commit1b537be8d43c7b7a41f6eee31fb1db5175405175 (patch)
treedb387c534a4c3bdb49e64cc04f680244d26202b1
parent47cfcda3c6a63a765f14b62e6ebbc3b6caadb75a (diff)
downloadscummvm-rg350-1b537be8d43c7b7a41f6eee31fb1db5175405175.tar.gz
scummvm-rg350-1b537be8d43c7b7a41f6eee31fb1db5175405175.tar.bz2
scummvm-rg350-1b537be8d43c7b7a41f6eee31fb1db5175405175.zip
Patch #902111: Change remaining random function calls to use RandomSource
svn-id: r13262
-rw-r--r--TODO6
-rw-r--r--backends/midi/adlib.cpp20
-rw-r--r--sound/fmopl.cpp3
-rw-r--r--sound/fmopl.h4
4 files changed, 12 insertions, 21 deletions
diff --git a/TODO b/TODO
index 1a71e3d65f..65db43a969 100644
--- a/TODO
+++ b/TODO
@@ -29,12 +29,6 @@ General
of the subdirs). Better would be to introduce a somewhat higher level API,
a replacement for File::open() which (optionally) takes a list of subdirs.
E.g. for Scumm, only certain files are to be expected in the VIDEO subdir).
-* Use RandomSource for all random numbers. Right now there are a few places
- where we don't:
- - sound/fmopl.cpp uses rand() in one function
- - backends/midi/adlib.cpp has its own random_nr() function.
- Any others?
-
Build System
============
diff --git a/backends/midi/adlib.cpp b/backends/midi/adlib.cpp
index 7fb0de39b1..6b6ebb3528 100644
--- a/backends/midi/adlib.cpp
+++ b/backends/midi/adlib.cpp
@@ -573,6 +573,8 @@ private:
bool _isOpen;
bool _game_SmallHeader;
+ static Common::RandomSource _rnd;
+
FM_OPL *_opl;
byte *_adlib_reg_cache;
SoundMixer *_mixer;
@@ -624,7 +626,6 @@ private:
void struct10_init(Struct10 * s10, InstrumentExtra * ie);
static byte struct10_ontimer(Struct10 * s10, Struct11 * s11);
static void struct10_setup(Struct10 * s10);
- static int random_nr(int a);
void mc_key_on(AdlibVoice *voice, AdlibInstrument *instr, byte note, byte velocity);
static void premix_proc(void *param, int16 *buf, uint len);
@@ -1230,7 +1231,7 @@ void MidiDriver_ADLIB::struct10_setup(Struct10 *s10) {
t = s10->table_a[f];
e = num_steps_table[lookup_table[t & 0x7F][b]];
if (t & 0x80) {
- e = random_nr(e);
+ e = _rnd.getRandomNumber(e);
}
if (e == 0)
e++;
@@ -1243,7 +1244,7 @@ void MidiDriver_ADLIB::struct10_setup(Struct10 *s10) {
t = s10->table_b[f];
d = lookup_volume(c, (t & 0x7F) - 31);
if (t & 0x80) {
- d = random_nr(d);
+ d = _rnd.getRandomNumber(d);
}
if (d + g > c) {
h = c - g;
@@ -1305,17 +1306,6 @@ void MidiDriver_ADLIB::adlib_playnote(int channel, int note) {
adlib_write(channel + 0xB0, oct | 0x20);
}
-int MidiDriver_ADLIB::random_nr(int a) {
- static byte _rand_seed = 1;
- if (_rand_seed & 1) {
- _rand_seed >>= 1;
- _rand_seed ^= 0xB8;
- } else {
- _rand_seed >>= 1;
- }
- return _rand_seed * a >> 8;
-}
-
void MidiDriver_ADLIB::part_key_off(AdlibPart *part, byte note) {
AdlibVoice *voice;
@@ -1564,3 +1554,5 @@ void MidiDriver_ADLIB::adlib_note_on(int chan, byte note, int mod) {
curnote_table[chan] = code;
adlib_playnote(chan, (int16) channel_table_2[chan] + code);
}
+
+Common::RandomSource MidiDriver_ADLIB::_rnd;
diff --git a/sound/fmopl.cpp b/sound/fmopl.cpp
index 60dacbfc33..0b3c1664a9 100644
--- a/sound/fmopl.cpp
+++ b/sound/fmopl.cpp
@@ -471,7 +471,8 @@ inline void OPL_CALC_CH(OPL_CH *CH) {
#define WHITE_NOISE_db 6.0
inline void OPL_CALC_RH(OPL_CH *CH) {
uint env_tam, env_sd, env_top, env_hh;
- int whitenoise = int((rand()&1) * (WHITE_NOISE_db / EG_STEP));
+ int whitenoise = int(oplRnd.getRandomNumber(1) * (WHITE_NOISE_db / EG_STEP));
+
int tone8;
OPL_SLOT *SLOT;
diff --git a/sound/fmopl.h b/sound/fmopl.h
index 509f0abc80..96db6196c1 100644
--- a/sound/fmopl.h
+++ b/sound/fmopl.h
@@ -27,6 +27,7 @@
#define FMOPL_H_
#include "common/scummsys.h"
+#include "common/util.h"
enum {
FMOPL_ENV_BITS_HQ = 16,
@@ -158,6 +159,9 @@ unsigned char OPLRead(FM_OPL *OPL, int a);
int OPLTimerOver(FM_OPL *OPL, int c);
void OPLWriteReg(FM_OPL *OPL, int r, int v);
void YM3812UpdateOne(FM_OPL *OPL, int16 *buffer, int length);
+
+static Common::RandomSource oplRnd; /* OPL random number generator */
+
#endif
// Factory method