epr_test.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Sekai - addons for the WORLD speech toolkit
  3. Copyright (C) 2016 Tobias Platen
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "epr.h"
  16. #include <math.h>
  17. #include <stdio.h>
  18. #include "common.h"
  19. float init_f[6] = {915.597, 1408.48, 1892.801, 4025.529, 4509.241, 6000};
  20. float init_bw[6] = {174.803, 167.995, 125.245, 411.338, 429.417, 50};
  21. float init_gain_db[6] = {20, 20, 10, 7, 5, 3};
  22. float init_controls[3] = {22.5, -7E-5, 77};
  23. int main() {
  24. int fs = 44100;
  25. EprResonance res[6];
  26. for (int i = 0; i < 6; i++) {
  27. res[i].f = init_f[i];
  28. res[i].bw = init_bw[i];
  29. res[i].gain_db = init_gain_db[i];
  30. EprResonanceUpdate(&res[i], fs);
  31. }
  32. EprSourceParams src;
  33. src.gaindb = init_controls[0];
  34. src.slope = init_controls[1];
  35. src.slopedepthdb = init_controls[2];
  36. printf("SRC: %f %f %f\n", src.gaindb, src.slope, src.slopedepthdb);
  37. for (int i = 0; i < 6; i++) {
  38. printf("RES[%i]: %f %f %f\n", i, res[i].f, res[i].bw, res[i].gain_db);
  39. }
  40. int fft_size = 1024 * 2;
  41. double *spectrogram = new double[fft_size / 2 + 1];
  42. double f0 = 300;
  43. for (int i = 0; i < fft_size / 2 + 1; i++) {
  44. double f = i * fs * 1.0 / fft_size;
  45. spectrogram[i] =
  46. exp(EprAtFrequency(&src, f, fs, res, 6) / TWENTY_OVER_LOG10);
  47. }
  48. EprSourceEstimate(spectrogram, fft_size, fs, f0, &src);
  49. printf("SRC: %f %f %f\n", src.gaindb, src.slope, src.slopedepthdb);
  50. double *residual = new double[fft_size / 2 + 1];
  51. EprVocalTractEstimate(spectrogram, fft_size, fs, f0, &src, residual, res, 6);
  52. for (int i = 0; i < 6; i++) {
  53. printf("RES[%i]: %f %f %f\n", i, res[i].f, res[i].bw, res[i].gain_db);
  54. }
  55. for (int i = 0; i < fft_size / 2 + 1; i++) {
  56. double f = i * fs * 1.0 / fft_size;
  57. double db = TWENTY_OVER_LOG10 * log(spectrogram[i]);
  58. printf("FRQ: %f %f\n", f, db - EprAtFrequency(&src, f, fs, res, 6));
  59. }
  60. }