Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating World #373

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tools/WORLD/src/cheaptrick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -205,12 +208,13 @@ 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;
// f0_floor and fs is used to determine fft_size;
// 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);
}
4 changes: 4 additions & 0 deletions tools/WORLD/src/d4c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(pow(2.0, 1.0 +
static_cast<int>(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);
Expand Down Expand Up @@ -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<int>(pow(2.0, 1.0 +
static_cast<int>(log(4.0 * fs / world::kFloorF0 + 1) / world::kLog2)));

Expand Down
13 changes: 7 additions & 6 deletions tools/WORLD/src/fft.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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];
}
}
}
Expand All @@ -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;
Expand All @@ -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];
}
}
}
Expand Down
53 changes: 34 additions & 19 deletions tools/WORLD/src/matlabfunctions.cpp
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -14,6 +15,7 @@
#include "world/matlabfunctions.h"

#include <math.h>
#include <stdint.h>

#include "world/constantnumbers.h"

Expand Down Expand Up @@ -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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not match with mmorise's commit, is there a reason?
mmorise/World@9a26692#diff-187e775cb821482add4032722c5e716aR262


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;
}
Expand Down
3 changes: 2 additions & 1 deletion tools/WORLD/src/world/cheaptrick.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef struct {
// This is defined as the struct for future update.
double q1;
double f0_floor;
int fft_size;
} CheapTrickOption;

//-----------------------------------------------------------------------------
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/WORLD/test/analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tools/WORLD/test/ctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tools/WORLD/test/synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tools/WORLD/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down