diff --git a/tools/WORLD/src/cheaptrick.cpp b/tools/WORLD/src/cheaptrick.cpp index 06e25441..2f052aeb 100644 --- a/tools/WORLD/src/cheaptrick.cpp +++ b/tools/WORLD/src/cheaptrick.cpp @@ -184,6 +184,9 @@ void CheapTrick(const double *x, int x_length, int fs, const double *time_axis, double **spectrogram) { int fft_size = GetFFTSizeForCheapTrick(fs, option); double *spectral_envelope = new double[fft_size]; + + void randn_reseed(void); + randn_reseed(); ForwardRealFFT forward_real_fft = {0}; InitializeForwardRealFFT(fft_size, &forward_real_fft); @@ -205,7 +208,7 @@ void CheapTrick(const double *x, int x_length, int fs, const double *time_axis, delete[] spectral_envelope; } -void InitializeCheapTrickOption(CheapTrickOption *option) { +void InitializeCheapTrickOption(int fs,CheapTrickOption *option) { // q1 is the parameter used for the spectral recovery. // Since The parameter is optimized, you don't need to change the parameter. option->q1 = -0.09; @@ -213,4 +216,5 @@ void InitializeCheapTrickOption(CheapTrickOption *option) { // We strongly recommend not to change this value unless you have enough // knowledge of the signal processing in CheapTrick. option->f0_floor = world::kFloorF0; + option->fft_size = GetFFTSizeForCheapTrick(fs, option); } diff --git a/tools/WORLD/src/d4c.cpp b/tools/WORLD/src/d4c.cpp index 0b31c01a..c9f0c3aa 100644 --- a/tools/WORLD/src/d4c.cpp +++ b/tools/WORLD/src/d4c.cpp @@ -261,6 +261,8 @@ void D4C(const double *x, int x_length, int fs, const double *time_axis, double **aperiodicity) { int fft_size_d4c = static_cast(pow(2.0, 1.0 + static_cast(log(4.0 * fs / world::kFloorF0 + 1) / world::kLog2))); + void randn_reseed(void); + randn_reseed(); ForwardRealFFT forward_real_fft = {0}; InitializeForwardRealFFT(fft_size_d4c, &forward_real_fft); @@ -314,6 +316,8 @@ void D4C(const double *x, int x_length, int fs, const double *time_axis, void D4C_coarse(const double *x, int x_length, int fs, const double *time_axis, const double *f0, int f0_length, int fft_size, const D4COption *option, double **aperiodicity) { + void randn_reseed(void); + randn_reseed(); int fft_size_d4c = static_cast(pow(2.0, 1.0 + static_cast(log(4.0 * fs / world::kFloorF0 + 1) / world::kLog2))); diff --git a/tools/WORLD/src/fft.cpp b/tools/WORLD/src/fft.cpp index 68181fb6..bafb20cb 100644 --- a/tools/WORLD/src/fft.cpp +++ b/tools/WORLD/src/fft.cpp @@ -1,6 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright 2012-2016 Masanori Morise. All Rights Reserved. +// Copyright 2012 Masanori Morise // Author: mmorise [at] yamanashi.ac.jp (Masanori Morise) +// Last update: 2018/01/21 // // This file represents the functions about FFT (Fast Fourier Transform) // implemented by Mr. Ooura, and wrapper functions implemented by M. Morise. @@ -28,7 +29,7 @@ static void BackwardFFT(fft_plan p) { p.input[1] = p.c_in[p.n / 2][0]; for (int i = 1; i < p.n / 2; ++i) { p.input[i * 2] = p.c_in[i][0]; - p.input[i * 2 + 1] = p.c_in[i][1]; + p.input[i * 2 + 1] = -p.c_in[i][1]; } rdft(p.n, -1, p.input, p.ip, p.w); for (int i = 0; i < p.n; ++i) p.out[i] = p.input[i] * 2.0; @@ -40,7 +41,7 @@ static void BackwardFFT(fft_plan p) { cdft(p.n * 2, -1, p.input, p.ip, p.w); for (int i = 0; i < p.n; ++i) { p.c_out[i][0] = p.input[i * 2]; - p.c_out[i][1] = p.input[i * 2 + 1]; + p.c_out[i][1] = -p.input[i * 2 + 1]; } } } @@ -53,7 +54,7 @@ static void ForwardFFT(fft_plan p) { p.c_out[0][1] = 0.0; for (int i = 1; i < p.n / 2; ++i) { p.c_out[i][0] = p.input[i * 2]; - p.c_out[i][1] = p.input[i * 2 + 1]; + p.c_out[i][1] = -p.input[i * 2 + 1]; } p.c_out[p.n / 2][0] = p.input[1]; p.c_out[p.n / 2][1] = 0.0; @@ -64,8 +65,8 @@ static void ForwardFFT(fft_plan p) { } cdft(p.n * 2, 1, p.input, p.ip, p.w); for (int i = 0; i < p.n; ++i) { - p.c_out[i][0] = p.input[i * 2]; - p.c_out[i][1] = p.input[i * 2 + 1]; + p.c_out[i][0] = p.input[i * 2]; + p.c_out[i][1] = -p.input[i * 2 + 1]; } } } diff --git a/tools/WORLD/src/matlabfunctions.cpp b/tools/WORLD/src/matlabfunctions.cpp index 03846f45..695fc925 100644 --- a/tools/WORLD/src/matlabfunctions.cpp +++ b/tools/WORLD/src/matlabfunctions.cpp @@ -1,6 +1,7 @@ //----------------------------------------------------------------------------- -// Copyright 2012-2016 Masanori Morise. All Rights Reserved. +// Copyright 2012 Masanori Morise // Author: mmorise [at] yamanashi.ac.jp (Masanori Morise) +// Last update: 2017/02/01 // // Matlab functions implemented for WORLD // Since these functions are implemented as the same function of Matlab, @@ -14,6 +15,7 @@ #include "world/matlabfunctions.h" #include +#include #include "world/constantnumbers.h" @@ -238,25 +240,38 @@ void interp1Q(double x, double shift, const double *y, int x_length, delete[] delta_y; } +// You must not use these variables. +// Note: +// I have no idea to implement the randn() and randn_reseed() without the +// global variables. If you have a good idea, please give me the information. +static uint32_t g_randn_x = 123456789; +static uint32_t g_randn_y = 362436069; +static uint32_t g_randn_z = 521288629; +static uint32_t g_randn_w = 88675123; + +void randn_reseed(void) { + g_randn_x = 123456789; + g_randn_y = 362436069; + g_randn_z = 521288629; + g_randn_w = 88675123; +} + double randn(void) { - static unsigned int x = 123456789; - static unsigned int y = 362436069; - static unsigned int z = 521288629; - static unsigned int w = 88675123; - unsigned int t; - t = x ^ (x << 11); - x = y; - y = z; - z = w; - - unsigned int tmp = 0; - for (int i = 0; i < 12; ++i) { - t = x ^ (x << 11); - x = y; - y = z; - z = w; - w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); - tmp += w >> 4; + uint32_t 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; + g_randn_w = (g_randn_w ^ (g_randn_w >> 19)) ^ (t ^ (t >> 8)); + + uint32_t tmp = g_randn_w >> 4; + for (int i = 0; i < 11; ++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; } diff --git a/tools/WORLD/src/world/cheaptrick.h b/tools/WORLD/src/world/cheaptrick.h index 29fd0cc5..eb4ae470 100644 --- a/tools/WORLD/src/world/cheaptrick.h +++ b/tools/WORLD/src/world/cheaptrick.h @@ -16,6 +16,7 @@ typedef struct { // This is defined as the struct for future update. double q1; double f0_floor; + int fft_size; } CheapTrickOption; //----------------------------------------------------------------------------- @@ -42,7 +43,7 @@ void CheapTrick(const double *x, int x_length, int fs, const double *time_axis, // Output: // option : Struct for the optional parameter. //----------------------------------------------------------------------------- -void InitializeCheapTrickOption(CheapTrickOption *option); +void InitializeCheapTrickOption(int fs, CheapTrickOption *option); //----------------------------------------------------------------------------- // GetFFTSizeForCheapTrick() calculates the FFT size based on the sampling diff --git a/tools/WORLD/test/analysis.cpp b/tools/WORLD/test/analysis.cpp index 03394279..42e8dfa7 100644 --- a/tools/WORLD/test/analysis.cpp +++ b/tools/WORLD/test/analysis.cpp @@ -139,7 +139,7 @@ void F0Estimation(double *x, int x_length, WorldParameters *world_parameters) { void SpectralEnvelopeEstimation(double *x, int x_length, WorldParameters *world_parameters) { CheapTrickOption option = {0}; - InitializeCheapTrickOption(&option); + InitializeCheapTrickOption(world_parameters->fs,&option); // This value may be better one for HMM speech synthesis. // Default value is -0.09. diff --git a/tools/WORLD/test/ctest.c b/tools/WORLD/test/ctest.c index add33d6b..651fcece 100644 --- a/tools/WORLD/test/ctest.c +++ b/tools/WORLD/test/ctest.c @@ -143,7 +143,7 @@ static void F0Estimation(double *x, int x_length, WorldParameters *world_paramet static void SpectralEnvelopeEstimation(double *x, int x_length, WorldParameters *world_parameters) { CheapTrickOption option = {0}; - InitializeCheapTrickOption(&option); + InitializeCheapTrickOption(world_parameters->fs,&option); // This value may be better one for HMM speech synthesis. // Default value is -0.09. diff --git a/tools/WORLD/test/synth.cpp b/tools/WORLD/test/synth.cpp index 345905ab..4d132e47 100644 --- a/tools/WORLD/test/synth.cpp +++ b/tools/WORLD/test/synth.cpp @@ -142,7 +142,7 @@ void F0Estimation(double *x, int x_length, WorldParameters *world_parameters) { void SpectralEnvelopeEstimation(double *x, int x_length, WorldParameters *world_parameters) { CheapTrickOption option = {0}; - InitializeCheapTrickOption(&option); + InitializeCheapTrickOption(world_parameters->fs,&option); // This value may be better one for HMM speech synthesis. // Default value is -0.09. diff --git a/tools/WORLD/test/test.cpp b/tools/WORLD/test/test.cpp index 4856855d..2efbef21 100644 --- a/tools/WORLD/test/test.cpp +++ b/tools/WORLD/test/test.cpp @@ -144,7 +144,7 @@ void F0Estimation(double *x, int x_length, WorldParameters *world_parameters) { void SpectralEnvelopeEstimation(double *x, int x_length, WorldParameters *world_parameters) { CheapTrickOption option = {0}; - InitializeCheapTrickOption(&option); + InitializeCheapTrickOption(world_parameters->fs, &option); // This value may be better one for HMM speech synthesis. // Default value is -0.09.