world.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. *
  3. * 音声分析合成法 WORLD by M. Morise
  4. *
  5. * WORLD.h
  6. * (c) M. Morise 2010-
  7. * edit and comment by HAL, kbinani
  8. *
  9. * This file is a part of WORLD system.
  10. * WORLD needs FFTW. Please install FFTW to use these files.
  11. * FFTW is here; http://www.fftw.org/
  12. *
  13. * notice: this comment is added by HAL.
  14. * Original files are on the web page below;
  15. * http://www.aspl.is.ritsumei.ac.jp/morise/world/
  16. *
  17. */
  18. // 現状で分かっているバグ
  19. // decimateForF0 : 開始直後・終了間際4サンプルくらいに誤差が入ります.
  20. #ifndef __world_h__
  21. #define __world_h__
  22. #include <algorithm>
  23. #include <fftw3.h>
  24. #include <stdlib.h>
  25. #include <math.h>
  26. #include "../stand.h"
  27. #ifndef PI
  28. #define PI 3.1415926535897932384
  29. #endif
  30. #ifndef max
  31. #define max(a,b) (((a) > (b)) ? (a) : (b))
  32. #endif
  33. #ifndef min
  34. #define min(a,b) (((a) < (b)) ? (a) : (b))
  35. #endif
  36. #ifndef __GNUC__
  37. // windowsならでは
  38. #pragma warning( disable : 4996 )
  39. #pragma comment(lib, "libfftw3-3.lib")
  40. //#pragma comment(lib, "libfftw3f-3.lib")
  41. //#pragma comment(lib, "libfftw3l-3.lib")
  42. #endif
  43. #define MAX_FFT_LENGTH 2048
  44. #define FLOOR 71.0
  45. #define FLOOR_F0 71.0
  46. #define DEFAULT_F0 150.0
  47. #define LOW_LIMIT 65.0
  48. // 71は,fs: 44100においてFFT長を2048にできる下限.
  49. // 70 Hzにすると4096点必要になる.
  50. // F0推定法 DIO : Distributed Inline-filter Operation
  51. void dio(double *x, int xLen, int fs, double framePeriod,
  52. double *timeAxis, double *f0);
  53. int getSamplesForDIO(int fs, int xLen, double framePeriod);
  54. // スペクトル包絡推定法 STAR : Synchronous Technique and Adroit Restoration
  55. int getFFTLengthForStar(int fs);
  56. void star(double *x, int xLen, int fs, double *timeAxis, double *f0,
  57. double **specgram, bool mode);
  58. void starGeneralBody(double *x, int xLen, int fs, double f0, double t, int fftl,
  59. double * sliceSTAR, double *waveform, double *powerSpec, fftw_complex *ySpec, fftw_plan *forwardFFT);
  60. // 非周期性指標推定法 PLATINUM : 名称未定
  61. void platinum(int fs, double *f0, int tLen,
  62. double **aperiodicity);
  63. void calculateAperiodicity(double *aperiodicity, int fftl, int fs, double *periodicSpec);
  64. // 非周期性指標推定法 PLATINUM from WORLD0.0.4
  65. void platinum_v4(double *x, int xLen, int fs, double *timeAxis, double *f0, double **specgram,
  66. double **residualSpecgram);
  67. void getWedgeList(double *x, int xLen, int vuvNum, int *stList, int *edList, int fs, double framePeriod, double *f0, int *wedgeList);
  68. int getPulseLocations(double *x, int xLen, double *totalPhase, int vuvNum, int *stList, int *edList, int fs, double framePeriod, int *wedgeList, double *pulseLocations);
  69. void getOneFrameResidualSpec(double *x, int xLen, int fs, int positionIndex, double framePeriod, double f0, double *specgram, int fftl, double *pulseLocations, int pCount,
  70. double *residualSpec, fftw_plan *forwardFFT, fftw_complex *tmpSpec, fftw_complex *starSpec, fftw_complex *ceps, double *tmpWave,
  71. fftw_plan minForward, fftw_plan minInverse);
  72. // WORLD Synthesis
  73. void synthesis(double *f0, int tLen, double **specgram, double **aperiodicity, int fftl, double framePeriod, int fs,
  74. double *synthesisOut, int xLen);
  75. void getMinimumPhaseSpectrum(double *inputSpec, fftw_complex *spectrum, fftw_complex *cepstrum, int fftl, fftw_plan forward, fftw_plan inverse);
  76. // WORLD Synthesis 0.0.4
  77. void synthesis_v4(double *f0, int tLen, double **specgram, double **residualSpecgram, int fftl, double framePeriod, int fs,
  78. double *synthesisOut, int xLen);
  79. //------------------------------------------------------------------------------------
  80. // Matlab 関数の移植
  81. double std_mat(double *x, int xLen);
  82. void inv(double **r, int n, double **invr);
  83. void fftfilt(double *x, int xlen, double *h, int hlen, int fftl, double *y);
  84. // ガウス雑音発生
  85. float randn(void);
  86. void histc(double *x, int xLen, double *y, int yLen, int *index);
  87. void interp1(double *t, double *y, int iLen, double *t1, int oLen, double *y1);
  88. long decimateForF0(double *x, int xLen, double *y, int r);
  89. void filterForDecimate(double *x, int xLen, double *y, int r);
  90. // matlabに順ずる丸め
  91. // gccのmath.hにあるdouble round(double)と被るので名前が変わってますです
  92. int c_round(double x);
  93. void diff(double *x, int xLength, double *ans);
  94. // 河原先生作成のMatlab関数interp1Hを移植.
  95. // 基本的には同じだが,配列の要素数を明示的に指定する必要がある.
  96. void interp1Q(double x, double shift, double *y, int xLength, double *xi, int xiLength, double *ans);
  97. #endif