platinum.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. *
  3. * 非周期性成分推定法 PLATINUM 0.0.1 by M. Morise
  4. *
  5. * platinum.cpp
  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. * (this file is from WORLD 0.0.1)
  17. *
  18. * platinum.cpp includes a set of functions
  19. * that supports PLATINUM 0.0.1.
  20. * Notice that aperiodicity of 0.0.1 is much different
  21. * from that of 0.0.4. Please use platinum function
  22. * for synthesis function.
  23. *
  24. */
  25. #include "world.h"
  26. #include <stdio.h> // for debug
  27. #include <stdlib.h>
  28. #include <math.h>
  29. // PLATINUMの実装は限定的.
  30. // 正規リリースにはもう少しマシなアルゴリズムを実装します.
  31. // Aperiodicity estimation based on PLATINUM
  32. // [0]から順番にu, b, fc, w0
  33. void platinum(int fs, double *f0, int tLen,
  34. double **aperiodicity)
  35. {
  36. int i, j;
  37. double u, b, fc, w0; // これらが保存されるパラメタ
  38. // double fl, fh, alpha;
  39. // デバッグ用につき固定値を設定する
  40. u = 0.8;
  41. b = 0.2;
  42. for(i = 0;i < tLen;i++)
  43. {
  44. if(f0[i] == 0)
  45. {
  46. for(j = 0;j < 4;j++)
  47. aperiodicity[i][j] = 0.0;
  48. }
  49. else
  50. {
  51. w0 = 0.01 / (f0[i]/20.0);
  52. fc = f0[i]*1273.0/32.0 + 87.5;
  53. aperiodicity[i][0] = u;
  54. aperiodicity[i][1] = b;
  55. aperiodicity[i][2] = fc;
  56. aperiodicity[i][3] = w0;
  57. }
  58. }
  59. return;
  60. }
  61. // periodicSpecはfftl/2+1の長さが必要
  62. void calculateAperiodicity(double *aperiodicity, int fftl, int fs, double *periodicSpec)
  63. {
  64. int i;
  65. double w;
  66. for(i = 0;i <= fftl/2; i++)
  67. {
  68. w = (double)(i * fs)/ (double)fftl;
  69. periodicSpec[i] = 1.0 / (1.0 + exp(-aperiodicity[3] * (w-aperiodicity[2])));
  70. periodicSpec[i] = aperiodicity[1]+aperiodicity[0]*(1.0 - periodicSpec[i]);
  71. // periodicSpec[i] = aperiodicity[1]+(aperiodicity[0]-aperiodicity[1]) /
  72. // (1.0 + exp(-aperiodicity[3]*(w-aperiodicity[2])));
  73. }
  74. }