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]; ForwardRealFFT forward_real_fft = {0}; InitializeForwardRealFFT(fft_size, &forward_real_fft); InverseRealFFT inverse_real_fft = {0}; InitializeInverseRealFFT(fft_size, &inverse_real_fft); double current_f0; for (int i = 0; i < f0_length; ++i) { current_f0 = f0[i] <= f0_floor ? world::kDefaultF0 : f0[i]; CheapTrickGeneralBody(x, x_length, fs, current_f0, fft_size, temporal_positions[i], option->q1, &forward_real_fft, &inverse_real_fft, spectral_envelope); for (int j = 0; j <= fft_size / 2; ++j) spectrogram[i][j] = spectral_envelope[j]; } DestroyForwardRealFFT(&forward_real_fft); DestroyInverseRealFFT(&inverse_real_fft); delete[] spectral_envelope; }
void D4C(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) { int fft_size_d4c = static_cast<int>(pow(2.0, 1.0 + static_cast<int>(log(4.0 * fs / world::kFloorF0 + 1) / world::kLog2))); ForwardRealFFT forward_real_fft = {0}; InitializeForwardRealFFT(fft_size_d4c, &forward_real_fft); int number_of_aperiodicities = static_cast<int>(MyMinDouble(world::kUpperLimit, fs / 2.0 - world::kFrequencyInterval) / world::kFrequencyInterval); // Since the window function is common in D4CGeneralBody(), // it is designed here to speed up. int window_length = static_cast<int>(world::kFrequencyInterval * fft_size_d4c / fs) * 2 + 1; double *window = new double[window_length]; NuttallWindow(window_length, window); double *coarse_aperiodicity = new double[number_of_aperiodicities + 2]; coarse_aperiodicity[0] = -60.0; coarse_aperiodicity[number_of_aperiodicities + 1] = 0.0; double *coarse_frequency_axis = new double[number_of_aperiodicities + 2]; for (int i = 0; i <= number_of_aperiodicities; ++i) coarse_frequency_axis[i] = static_cast<double>(i) * world::kFrequencyInterval; coarse_frequency_axis[number_of_aperiodicities + 1] = fs / 2.0; double *frequency_axis = new double[fft_size / 2 + 1]; for (int i = 0; i <= fft_size / 2; ++i) frequency_axis[i] = static_cast<double>(i) * fs / fft_size; for (int i = 0; i < f0_length; ++i) { if (f0[i] == 0) { for (int j = 0; j <= fft_size / 2; ++j) aperiodicity[i][j] = 0.0; continue; } D4CGeneralBody(x, x_length, fs, MyMaxDouble(f0[i], world::kFloorF0), fft_size_d4c, time_axis[i], number_of_aperiodicities, window, window_length, &forward_real_fft, &coarse_aperiodicity[1]); // Linear interpolation to convert the coarse aperiodicity into its // spectral representation. interp1(coarse_frequency_axis, coarse_aperiodicity, number_of_aperiodicities + 2, frequency_axis, fft_size / 2 + 1, aperiodicity[i]); for (int j = 0; j <= fft_size / 2; ++j) aperiodicity[i][j] = pow(10.0, aperiodicity[i][j] / 20.0); } DestroyForwardRealFFT(&forward_real_fft); delete[] coarse_frequency_axis; delete[] coarse_aperiodicity; delete[] window; delete[] frequency_axis; }
void Star(const double *x, int x_length, int fs, double frame_period, const double *f0, int f0_length, double **spectrogram) { int fft_size = GetFFTSizeForStar(fs); double *star_spectrum = new double[fft_size]; // Following three variables are shared in StarGeneralBody() ForwardRealFFT forward_real_fft = {0}; InitializeForwardRealFFT(fft_size, &forward_real_fft); double current_f0; for (int i = 0; i < f0_length; ++i) { current_f0 = f0[i] <= world::kFloorF0 ? world::kDefaultF0 : f0[i]; StarGeneralBody(x, x_length, fs, current_f0, frame_period * i / 1000.0, &forward_real_fft, star_spectrum); for (int j = 0; j <= fft_size / 2; ++j) spectrogram[i][j] = star_spectrum[j]; } DestroyForwardRealFFT(&forward_real_fft); delete[] star_spectrum; }
void CheapTrick(double *x, int x_length, int fs, double *time_axis, double *f0, int f0_length, double **spectrogram) { int fft_size = GetFFTSizeForCheapTrick(fs); double *spectral_envelope = new double[fft_size]; ForwardRealFFT forward_real_fft = {0}; InitializeForwardRealFFT(fft_size, &forward_real_fft); InverseRealFFT inverse_real_fft = {0}; InitializeInverseRealFFT(fft_size, &inverse_real_fft); double current_f0; for (int i = 0; i < f0_length; ++i) { current_f0 = f0[i] <= world::kFloorF0 ? world::kDefaultF0 : f0[i]; CheapTrickGeneralBody(x, x_length, fs, current_f0, fft_size, time_axis[i], &forward_real_fft, &inverse_real_fft, spectral_envelope); for (int j = 0; j <= fft_size / 2; ++j) spectrogram[i][j] = spectral_envelope[j]; } DestroyForwardRealFFT(&forward_real_fft); DestroyInverseRealFFT(&inverse_real_fft); delete[] spectral_envelope; }