Skip to content

Commit

Permalink
reseed the pseudo-random number generator each time CheapTrick is cal…
Browse files Browse the repository at this point in the history
…led otherwise the results are not repeatable.
  • Loading branch information
gillesdegottex committed Mar 8, 2018
1 parent 9b06a08 commit 9a26692
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/cheaptrick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ void CheapTrick(const double *x, int x_length, int fs,
const double *temporal_positions, const double *f0, int f0_length,
const CheapTrickOption *option, double **spectrogram) {
int fft_size = option->fft_size;

randn_reseed();

double f0_floor = GetF0FloorForCheapTrick(fs, fft_size);
double *spectral_envelope = new double[fft_size];

Expand Down
45 changes: 26 additions & 19 deletions src/matlabfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,33 @@ void interp1Q(double x, double shift, const double *y, int x_length,
delete[] delta_y;
}

static unsigned int g_randn_x = 123456789;
static unsigned int g_randn_y = 362436069;
static unsigned int g_randn_z = 521288629;
static unsigned int g_randn_w = 88675123;

void randn_reseed() {
g_randn_x = 123456789;
g_randn_y = 362436069;
g_randn_z = 521288629;
g_randn_w = 88675123;
}

double randn(void) {
static uint32_t x = 123456789;
static uint32_t y = 362436069;
static uint32_t z = 521288629;
static uint32_t w = 88675123;
uint32_t t;
t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));

uint32_t tmp = w >> 4;
for (int i = 0; i < 11; ++i) {
t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
tmp += w >> 4;
unsigned int t;
t = g_randn_x ^ (g_randn_x << 11);
g_randn_x = g_randn_y;
g_randn_y = g_randn_z;
g_randn_z = g_randn_w;

unsigned int tmp = 0;
for (int i = 0; i < 12; ++i) {
t = g_randn_x ^ (g_randn_x << 11);
g_randn_x = g_randn_y;
g_randn_y = g_randn_z;
g_randn_z = g_randn_w;
g_randn_w = (g_randn_w ^ (g_randn_w >> 19)) ^ (t ^ (t >> 8));
tmp += g_randn_w >> 4;
}
return tmp / 268435456.0 - 6.0;
}
Expand Down
5 changes: 5 additions & 0 deletions src/world/matlabfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ void interp1Q(double x, double shift, const double *y, int x_length,
//-----------------------------------------------------------------------------
double randn(void);

//-----------------------------------------------------------------------------
// randn_reseed() force to seed the pseudorandom generator using initial values.
//-----------------------------------------------------------------------------
void randn_reseed(void);

//-----------------------------------------------------------------------------
// fast_fftfilt() carries out the convolution on the frequency domain.
//
Expand Down

0 comments on commit 9a26692

Please sign in to comment.