Browse Source

Allow random::init() to be called when already initialized.

tags/v2.0.0
Andrew Belt 5 years ago
parent
commit
20a875ff10
2 changed files with 13 additions and 2 deletions
  1. +9
    -2
      src/engine/Engine.cpp
  2. +4
    -0
      src/random.cpp

+ 9
- 2
src/engine/Engine.cpp View File

@@ -270,7 +270,7 @@ static void Cable_step(Cable* that) {
} }




static void Engine_step(Engine* that) {
static void Engine_stepModules(Engine* that) {
Engine::Internal* internal = that->internal; Engine::Internal* internal = that->internal;


// Param smoothing // Param smoothing
@@ -296,6 +296,12 @@ static void Engine_step(Engine* that) {


// Step cables // Step cables
for (Cable* cable : that->internal->cables) { for (Cable* cable : that->internal->cables) {
// // Check that the output is finite
// float v = cable->outputModule->outputs[cable->outputId].getVoltage();
// if (!std::isfinite(v)) {
// // Automatically disable module
// that->disableModule(cable->outputModule, true);
// }
Cable_step(cable); Cable_step(cable);
} }


@@ -422,6 +428,7 @@ void Engine::clear() {


void Engine::step(int frames) { void Engine::step(int frames) {
initMXCSR(); initMXCSR();
random::init();


// Set sample rate // Set sample rate
if (internal->sampleRate != settings::sampleRate) { if (internal->sampleRate != settings::sampleRate) {
@@ -451,7 +458,7 @@ void Engine::step(int frames) {


// Step modules // Step modules
for (int i = 0; i < frames; i++) { for (int i = 0; i < frames; i++) {
Engine_step(this);
Engine_stepModules(this);
} }
} }
else { else {


+ 4
- 0
src/random.cpp View File

@@ -30,6 +30,10 @@ static uint64_t xoroshiro128plus_next(void) {
} }


void init() { void init() {
// Do nothing if already initialized
if (xoroshiro128plus_state[0] || xoroshiro128plus_state[1])
return;

struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
xoroshiro128plus_state[0] = tv.tv_sec; xoroshiro128plus_state[0] = tv.tv_sec;


Loading…
Cancel
Save