Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

retuner.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // -----------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2009-2011 Fons Adriaensen <fons@linuxaudio.org>
  4. // Modified by falkTX on Jan-Apr 2015 for inclusion in Carla
  5. //
  6. // This program is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation; either version 2 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. //
  20. // -----------------------------------------------------------------------
  21. #ifndef __RETUNER_H
  22. #define __RETUNER_H
  23. #include <fftw3.h>
  24. #include <zita-resampler/resampler.h>
  25. namespace AT1 {
  26. class Retuner
  27. {
  28. public:
  29. Retuner (int fsamp);
  30. ~Retuner (void);
  31. int process (int nfram, float *inp, float *out);
  32. void set_refpitch (float v)
  33. {
  34. _refpitch = v;
  35. }
  36. void set_notebias (float v)
  37. {
  38. _notebias = v / 13.0f;
  39. }
  40. void set_corrfilt (float v)
  41. {
  42. _corrfilt = (4 * _frsize) / (v * _fsamp);
  43. }
  44. void set_corrgain (float v)
  45. {
  46. _corrgain = v;
  47. }
  48. void set_corroffs (float v)
  49. {
  50. _corroffs = v;
  51. }
  52. void set_notemask (int k)
  53. {
  54. _notemask = k;
  55. }
  56. int get_noteset (void)
  57. {
  58. int k;
  59. k = _notebits;
  60. _notebits = 0;
  61. return k;
  62. }
  63. float get_error (void)
  64. {
  65. return 12.0f * _error;
  66. }
  67. private:
  68. void findcycle (void);
  69. void finderror (void);
  70. float cubic (float *v, float a);
  71. int _fsamp;
  72. int _ifmin;
  73. int _ifmax;
  74. bool _upsamp;
  75. int _fftlen;
  76. int _ipsize;
  77. int _frsize;
  78. int _ipindex;
  79. int _frindex;
  80. int _frcount;
  81. float _refpitch;
  82. float _notebias;
  83. float _corrfilt;
  84. float _corrgain;
  85. float _corroffs;
  86. int _notemask;
  87. int _notebits;
  88. int _lastnote;
  89. int _count;
  90. float _cycle;
  91. float _error;
  92. float _ratio;
  93. float _phase;
  94. bool _xfade;
  95. float _rindex1;
  96. float _rindex2;
  97. float *_ipbuff;
  98. float *_xffunc;
  99. float *_fftTwind;
  100. float *_fftWcorr;
  101. float *_fftTdata;
  102. fftwf_complex *_fftFdata;
  103. fftwf_plan _fwdplan;
  104. fftwf_plan _invplan;
  105. Resampler _resampler;
  106. };
  107. }
  108. #endif